<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户权限管理</title>
    <script type="text/javascript" src="/static/js/jquery.js"></script>
    <script type="text/javascript" src="/static/js/jquery.unobtrusive-ajax.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/js/easyui-lang-zh_CN.js"></script>
    <link href="/static/css/themes/default/easyui.css" rel="stylesheet" />
    <link href="/static/css/themes/icon.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {  //页面加载完成后
            $(".selectActions").click(function () {  //为类绑定点击事件
                bindSetUserAction($(this));

            })
            $(".btnClearActions").click(function () {
                bindDeleteUserAction($(this));
            })
        })
       function bindSetUserAction(control) {
           var userId = {{.userInfo.Id}};
           // console.log(userId);
           var actionId = control.attr("ids")
           // console.log(actionId);
           var isPass = control.val();
           $.post("/Admin/UserInfo/SetUserAction",{"userId":userId,"actionId":actionId,"isPass":isPass},function (data) {
               if (data.flag=="ok"){
                   $.messager.alert("提示","用户权限修改成功！","info")
               }else {
                   $.messager.alert("提示","用户权限修改失败！","error")
               }
           })
       }
       function bindDeleteUserAction(control) {
           var userId = {{.userInfo.Id}};
           var actionId = control.attr("ids")
           $.post("/Admin/UserInfo/DeleteUserAction",{"userId":userId,"actionId":actionId},function (data) {
                if (data.flag=="ok"){
                    control.parent().find(".selectActions").removeAttr("checked")
                    $.messager.alert("提示","用户权限删除成功！","info")
                }else {
                    $.messager.alert("提示","用户权限删除失败！","error")
                }
           })
       }
    </script>
</head>
<body>
为用户<span style="font-size: 14px;color:red;font-weight: bolder">{{.userInfo.UserName}}</span>分配权限
<table width="100%">
    <tr><td>编号</td><td>权限名称</td><td>Url</td><td>操作</td></tr>
{{range .allActions}}
    <tr>
        <td>{{.Id}}</td>
        <td>{{.ActionInfoName}}</td>
        <td>{{.Url}}</td>
        <td>
        {{if checkUserAction $.userExtActions .Id}}
            {{if checkUserActionIsPass $.userExtActions .Id}}
                <label for="cba_{{.Id}}">允许</label>
                <input type="radio" value="1" class="selectActions" name="cba_{{.Id}}" ids="{{.Id}}" checked="checked">
                <label for="cba_{{.Id}}">禁止</label>
                <input type="radio" value="0" class="selectActions" name="cba_{{.Id}}" ids="{{.Id}}">
            {{else}}
                <label for="cba_{{.Id}}">允许</label>
                <input type="radio" value="1" class="selectActions" name="cba_{{.Id}}" ids="{{.Id}}">
                <label for="cba_{{.Id}}">禁止</label>
                <input type="radio" value="0" class="selectActions" name="cba_{{.Id}}" ids="{{.Id}}" checked="checked">
            {{end}}
        {{else}}
            <label for="cba_{{.Id}}">允许</label>
            <input type="radio" value="1" class="selectActions" name="cba_{{.Id}}" ids="{{.Id}}">
            <label for="cba_{{.Id}}">禁止</label>
            <input type="radio" value="0" class="selectActions" name="cba_{{.Id}}" ids="{{.Id}}">
        {{end}}
            <input type="button" value="删除" class="btnClearActions" ids="{{.Id}}">
        </td>
    </tr>
{{end}}
</table>
</body>
</html>